// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "DBManager/Service/Result/StiffnessMatrix/StiffnessMatrixService.h"

#include <cstring>
#include <vector>

#include <gtest/gtest.h>

#include "DataStructure/Common/Constant.h"
#include "DataStructure/Common/Status.h"

#include "DBManager/UnitTest/HDF5/TestDB.h"

using namespace SG::DataStructure::FEM;
using namespace SG::DBManager;

TEST (O_StiffnessMatrixServiceTest, Default)
{
    try
    {
        auto service = DB::ServiceFactory->get<IStiffnessMatrixService> ();

        // 保存矩阵
        std::vector<SG::Algebra::Matrixd> saveData;
        for (SG::DataStructure::Common::Id i = 0; i < 10; i++)
        {
            saveData.emplace_back (12, 12, i);
        }

        service->Add (ElementTypes::ELETYPE_Bar, saveData);

        // 修改数据 测试覆盖功能
        saveData[0][0][0] = 666;
        service->Add (ElementTypes::ELETYPE_Bar, saveData);

        // 查询矩阵
        std::vector<SG::Algebra::Matrixd> result;

        // 是否获取成功
        ASSERT_EQ (service->Get (ElementTypes::ELETYPE_Bar, result), SG::DataStructure::Common::Status::STATUS_Success);
        ASSERT_EQ (result.size (), 10);
        ASSERT_EQ (saveData, result);
        ASSERT_EQ (result[0][0][0], 666);
    }
    catch (const std::exception& e)
    {
        std::cerr << e.what () << '\n';
    }
}